<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    body{
      margin-top: 50px;
      border: 5px solid red;
      height: 2000px;
    }
    #div1 {
      background: red;
      position: fixed;
      top: 20px;
      z-index: -1;
    }
    #div2{
      background: green;
      position: sticky;
      /*  */
      top: -1px;
      /* z-index: 99999; */
    }
  </style>
</head>

<body>
  <div id="div1">123456</div>
  <div id="div2">1234512345678io</div>

</body>

</html>